$(function(){
	showCondition(true, 1, 1, 1, [0, 0, 1, 1, 1,0]);//加载查询条件
	var controlDeps = ""; //所辖科室
	// 获取当前登录的科室和科室名
	$.ajax({
		url : "DepCliMonitor/getRoleName.dhc",
		async : false,
		type : "POST",
		success : function(result) {
			controlDeps = result.depCode + ",";//加上一个, 保证科室code 都能完整匹配 因为下面要用index 防止 abc 在abcd中的情况
		}
	});
	//加载科室信息
	$.post(contextPath + "/DrgsIndexCal/findAllDepByHospCode.dhc").done(function(res) {
		var deps = res.data;
		//过滤
		deps = deps.filter(function(t) {
			var tmpDepCode = t.DEPCODE
			tmpDepCode = tmpDepCode + ",";
			var judge = false;
			var r = controlDeps.indexOf(tmpDepCode);
			if(r>=0)
			{
				judge = true;
			}
			return judge;
		})
		$CommonUI.combobox($("#" + tabId + " #depID"), deps, "DEPNAME","DEPCODE", {
			"height" : 30,// 设定框的高度
			"onSelect" : function(n, o) {
				paramTabPage[tabId].oldDepCode = n.DEPCODE;
				callSure(n.DEPCODE);
			} ,
			"onLoadSuccess" : function(){ 
				var data = $("#"+tabId+" #depID").combobox('getData');
				if(data.length>0 && paramTabPage[tabId].oldDepCode){
					$("#"+tabId+" #depID").combobox('setValue',paramTabPage[tabId].oldDepCode);
				}
				else
				{
					$("#"+tabId+" #depID").combobox('setValue',deps[0].DEPCODE);
				}
			} 
		});
		var selectedDepCode = $("#"+tabId+" #depID").combobox("getValue");
		callSure(selectedDepCode);
	});
	
	function callSure(depCode){
		paramTabPage[tabId].depCode = depCode;
		loadDepDisGroupPie(depCode);
		loadDepDisGroupTable(depCode);
		loadDepDisGroupScatter(depCode);
	}
})
/**
 * 
 * @ Discription:加载科室重点病组饼图信息
 * @Autor ：mazhaoyan
 * @param depCode 科室代码
 * void
 * depKeyDiseaseGroupAnalysis.js
 * 2017年8月10日下午2:01:08
 */
function loadDepDisGroupPie(depCode){	
	var param=drgUI.setAjaxData(tabId);
	param.pardepCode=depCode;
	$.post(contextPath + "/keyDisGroup/getDisGroupCollectInfo.dhc", param).done(function(res){
		if(res&&res.data&& res.data.length>0){
			var data = res.data[0] ;
			//环形图
			var labelTop = {
				    normal : {
				        label : {
				            show : true,
				            position : 'center',
				            formatter : function (params){
				            	return params.series.data[1].value+"/"+params.series.data[0].value ;
				            },
				            textStyle: {
				                baseline : 'bottom',
				                color: '#000'
				            }
				        },
				        labelLine : {
				            show : false
				        }
				    }
				};
				var labelFromatter = {
				    normal : {
				        label : {
				            formatter : function (params){
				            	return (params.series.data[1].value/params.series.data[0].value*100).toFixed(2) + '%'
				            },
				            textStyle: {
				                baseline : 'top'
				            }
				        }
				    }
				}
				var labelBottom = {
				    normal : {
				        color: '#ccc',
				        label : {
				            show : true,
				            position : 'center'
				        },
				        labelLine : {
				            show : false
				        }
				    },
				    emphasis: {
				        color: 'rgba(0,0,0,0)'
				    }
				};
				var radius = [50, 70];
				var legend={left : 120,bottom : 'bottom',itemGap: 250,data:['重点病组个数','重点病组入组病例数','重点病组总权重']};
				var series=[
						        {
						            type : 'pie',
						            center : ['15%', '40%'],
						            radius : radius,
						            avoidLabelOverlap:false,
						            label: {
						                normal: {
						                	show : true,
								            position : 'center',
								            formatter : function(){
								            	var per = 0;
								            	if(data.GROUPCNT>0){
								            		per = (100*data.KEYGROUPCNT/data.GROUPCNT).toFixed(2);
							            		}
								            	return data.KEYGROUPCNT+"/"+data.GROUPCNT+"\n" + per+"%";
								            },
								            textStyle: {
								                baseline : 'bottom'
								            }
						                }
						            },
						            data : [
						                {name:'重点病组个数', value:data.KEYGROUPCNT==null?0:data.KEYGROUPCNT},
						                {name:'other', value:(data.GROUPCNT==null?0:data.GROUPCNT)-(data.KEYGROUPCNT==null?0:data.KEYGROUPCNT)}
						            ]
						        },
						        {
						            type : 'pie',
						            center : ['45%', '40%'],
						            radius : radius,
						            avoidLabelOverlap:false,
						            label: {
						                normal: {
						                	show : true,
								            position : 'center',
								            formatter : function(){
								            	var per = 0;
								            	if(data.CASECNT>0){
								            		per = (100*data.KEYCASECNT/data.CASECNT).toFixed(2);
							            		}
								            	return data.KEYCASECNT+"/"+data.CASECNT+"\n" + per+"%";
								            },
								            textStyle: {
								                baseline : 'bottom'
								            }
						                }
						            },
						            data : [
						                {name:'重点病组入组病例数', value:data.KEYCASECNT==null?0:data.KEYCASECNT},
						                {name:'other', value:(data.CASECNT==null?0:data.CASECNT)-(data.KEYCASECNT==null?0:data.KEYCASECNT)}
						            ]
						        },
						        {
						            type : 'pie',
						            center : ['75%', '40%'],
						            radius : radius,
						            avoidLabelOverlap:false,
						            label: {
						                normal: {
						                	show : true,
								            position : 'center',
								            formatter : function(){
								            	var per = 0;
								            	if(data.KEYTOTALWEIGHT==null){
								            		data.KEYTOTALWEIGHT = 0;
							            		}
								            	if(data.TOTALWEIGHT==null){
								            		data.TOTALWEIGHT = 0;
							            		}
								            	if(data.TOTALWEIGHT>0){
								            		per = (100*data.KEYTOTALWEIGHT/data.TOTALWEIGHT).toFixed(2);
							            		}
								            	return data.KEYTOTALWEIGHT+"/"+data.TOTALWEIGHT+"\n" + per+"%";
								            },
								            textStyle: {
								                baseline : 'bottom'
								            }
						                }
						            },
						            data : [
						                {name:'重点病组总权重', value:data.KEYTOTALWEIGHT==null?0:data.KEYTOTALWEIGHT},
						                {name:'other', value:(data.TOTALWEIGHT==null?0:data.TOTALWEIGHT)-(data.KEYTOTALWEIGHT==null?0:data.KEYTOTALWEIGHT)}
						            ]
						        }
						    ];
			doughnutChart($('#'+tabId+' #depKeyGroupPieChart'),legend,series);
		}
	});
//	
//	$.post(contextPath + "/keyDisGroup/getDisGroupCollectInfo.dhc",
//	{
//		'dateFrom': paramTabPage[tabId].dateFrom,
//		'dateTo': paramTabPage[tabId].dateTo,
//		'pardepCode':depCode
//	}).done(function(res){});
}
/**
 * 
 * @ Discription: 加载重点病组的 指标信息
 * @Autor ：mazhaoyan
 * @param depCode
 * void
 * depKeyDiseaseGroupAnalysis.js
 * 2017年8月10日下午8:48:29
 */
function loadDepDisGroupTable(depCode){	
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc = "0";
	param.monitorType = "drgs";
	param.quotaCode = "InCaseCnt,CMI,TotalWeight,AvgDays,AvgFee,RiskLevel,DeadRatio";
	param.isKeyDisGroup = "1";
	param.groupType = "";
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(res){
		var data = res.data;
		// 重点病组表格展示的列
		var columns =  [
			                {
			                	 "data":"code",
			                	 "render":function(obj, type, full){
			                		 return  "("+full.ccode+")"+full.ddesc ;
			                	 }
		                	},
		                  	{"data": "InCaseCnt",
		                		"render":function(obj, type, full) {
		                			  if(full.InCaseCnt == 0){
		                				  return full.InCaseCnt ;
		                			  } else {
	    		                    	  return "<a href=\"javascript:void(0);\" onclick= \"loadCaseDtl('入组病例数','"+full.ccode+"','drgs', 'InCaseCnt')\">"+full.InCaseCnt+"</a>";
		                			  }
    		                    }
	                  		},
		                  	{"data": "CMI"},
		                  	{"data": "TotalWeight"},
		                  	{"data": "AvgDays"},
		                  	{"data": "AvgFee"},
		                  	{"data": "RiskLevel",
		                  		"render":function(obj, type, full){
		                  			var str = "";
		                  			switch(Number(full.RiskLevel))
		    						{
		    					        case 0: {
		    				                str = "无风险" ;break ;
		    					        }
		    					        case 1: {
		    					        	str = "低风险" ;break ;
		    					        }
		    					        case 2: {
		    					        	str = "中低风险" ;break ;
		    					        }
		    					        case 3: {
		    					        	str = "中高风险" ;break ;
		    					        }
		    					        case 4: {
		    					        	str = "高风险" ;break ;
		    					        }
		    						}
			                		 return  str ;
			                	 }
		                  	},
		                  	{"data": "DeadRatio"}
				         ] ;
		var paramsDataTables={autoWidth:false,tableTitle:'重点病组指标情况表'};
		$("#"+tabId+" #depKeyGroupTable").dataTableBasic(columns,data,paramsDataTables);
	});

}

function loadCaseDtl(title, ccode, monitorType, quotaCode){
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc = "0";
	param.quotaCode = quotaCode;
	param.caseLinkCode = quotaCode;
	param.title = title;
	if(ccode){
		if(monitorType == "depGroup"){
			param.depGroupCode=ccode;
		}else if(monitorType == "dep"){
			param.depCode=ccode;
		}else if(monitorType == "ward"){
			param.wardCode=ccode;
		}else if(monitorType == "clinic"){
			param.groupName=ccode;
		}else if(monitorType == "mdc"){
			param.mdcCode=ccode;
		}else if(monitorType == "adrg"){
			param.adrgCode=ccode;
		}else if(monitorType == "drgs"){
			param.drgCode=ccode;
		}
	}
	openTab('/pages/drgscommon/case.jsp', title+"明细", "caseDtl"+monitorType+ccode+quotaCode, "caseDtl"+monitorType+ccode+quotaCode, param);
}
/**
 * 
 * @ Discription:加载科室重点病组散点图
 * @Autor ：mazhaoyan
 * @param depCode
 * void
 * depKeyDiseaseGroupAnalysis.js
 * 2017年8月11日上午8:45:10
 */
function loadDepDisGroupScatter(depCode) {
	//初始化查询条件
	var param=drgUI.setAjaxData(tabId);
	param.isGetCc = "1";
	param.monitorType = "drgs";
	param.isKeyDisGroup = "1";
	param.groupType = "";
	var quotass = [
		              {quotaCode_1:"AvgDays", quotaName_1:"平均住院日", quotaDirection_1:-1, quotaCode_2:"AvgFee", quotaName_2:"次均费用", quotaDirection_2:-1},
		              {quotaCode_1:"AvgFee", quotaName_1:"次均费用", quotaDirection_1:-1, quotaCode_2:"DrugRatio", quotaName_2:"药占比", quotaDirection_2:-1}
	              ];
	var compareType = $("#searchcq").children().eq(3).find("a.active").attr("data-value");
	//清空
	$("#"+tabId+" #quota2Select").empty();
	$("#"+tabId+" #quota2SelectContent").empty();
	$("#"+tabId+" #quota2Select").html('<div class="btn-clickable btnslider" style="float:right;">环比变化幅度<i class="fa fa-cubes" aria-hidden="true"></i></div>');
	var desc="超标";//控制显示达标还是超标的变量
	for(var o in quotass){
		var str;
		if(o==0){
			str = $('<li role="presentation" class="quotasTab active" style="margin-right: 20px;">'
					+'<a href="#depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'" role="tab" data-index='+o+' data-toggle="tab">'+quotass[o].quotaName_1+'和'+quotass[o].quotaName_2+'</a>'	
					+'</li>');
			str.appendTo($("#"+tabId+" #quota2Select"));
			$('<div role="tabpanel" class="tab-pane active" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'">'
				+'	<div class="col-xs-12" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-chart" style=" height: 400px;padding: 10px 10px;"></div>'
				+'  <div class="col-xs-12" style="padding: 10px 10px;"><table id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table" class="table table-striped" style="border: solid 1px #ccc;"><tr><td style="width:10%">第一象限<br>(均'+desc+')</td><td></td></tr><tr><td>第二象限<br>('+quotass[o].quotaName_2+desc+')</td><td></td></tr><tr><td>第三象限<br>(均未'+desc+')</td><td></td></tr><tr><td>第四象限<br>('+quotass[o].quotaName_1+desc+')</td><td></td></tr></table><div>'
				+'</div>').appendTo($("#"+tabId+" #quota2SelectContent"))
		}else{
			str = $('<li role="presentation" class="quotasTab" style="margin-right: 20px;">'
					+'<a href="#depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'" role="tab" data-index='+o+' data-toggle="tab">'+quotass[o].quotaName_1+'和'+quotass[o].quotaName_2+'</a>'	
					+'</li>');
			str.appendTo($("#"+tabId+" #quota2Select"))
			$('<div role="tabpanel" class="tab-pane" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'">'
				+'	<div class="col-xs-12" id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-chart" style=" height: 400px;padding: 10px 10px;"></div>'
				+'  <div class="col-xs-12" style="padding: 10px 10px;"><table id="depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table" class="table table-striped" style="border: solid 1px #ccc; "><tr><td style="width:10%">第一象限<br>(均'+desc+')</td><td></td></tr><tr><td>第二象限<br>('+quotass[o].quotaName_2+desc+')</td><td></td></tr><tr><td>第三象限<br>(均未'+desc+')</td><td></td></tr><tr><td>第四象限<br>('+quotass[o].quotaName_1+desc+')</td><td></td></tr></table><div>'
				+'</div>').appendTo($("#"+tabId+" #quota2SelectContent"))
		}
		//如果比较类型为无，则页面底部的科室象限分布表格不显示
		if(compareType=='none'){
			$('#'+tabId+' #depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table').fadeOut();
		}
		else{
			$('#'+tabId+' #depQuad'+quotass[o].quotaCode_1+quotass[o].quotaCode_2+'-table').fadeIn();
		}
		//tab页签点击事件
		str.find("a").bind("click", function(){
			var index = $(this).attr("data-index");
			var quotas = quotass[index];
			if(quotas.chartType==0){
				$("#"+tabId+" .btnslider").removeClass("btn-success");
				$("#"+tabId+" .btnslider").addClass("btn-warning");
			}else{
				$("#"+tabId+" .btnslider").removeClass("btn-warning");
				$("#"+tabId+" .btnslider").addClass("btn-success");
			}
			if(quotas.loading == 1) return;
			quotas.ajaxCount = 4;
			if(index==2||index==3){
				quotas.ajaxCount = 5;
			}
			var datas = [];
			var datasyy = [];
			var datassort = [];
			//查询指标数据,本期和管理目标
			var p1 = jQuery.extend(true, {}, param);
			p1['monitorType']='drgs';
			ajaxRequest("Base", p1, function(data){
				datas = data;
				if(compareType=='none'){//如果比较类型为无，则不获取比较值
					p1.isGetCc=0;
				}
				p1.compareType = compareType;
				ajaxRequest(quotas.quotaCode_1, p1, function(data, quotaCode){
					if(datas && data) {
						mergeListcc(datas, data,'ccode','',quotaCode);
					}
					quotas.ajaxCount--;
				})
				ajaxRequest(quotas.quotaCode_2, p1, function(data, quotaCode){
					if(datas && data) {
						mergeListcc(datas, data,'ccode','',quotaCode);
					}
					quotas.ajaxCount--;
				})
				if(index==2||index==3){//添加求总权重的查询
					var pTemp = jQuery.extend(true, {}, p1);
					pTemp.isGetCc=0;
					ajaxRequest(quotas.quotaCode_3, pTemp, function(data, quotaCode){
						for(var n in data){
							datas[n]['symbolValue']=data[n].QuotaValue;//决定散点图点的大小的值
						}
						quotas.ajaxCount--;
					})
				}
			});
			//查询指标数据,上期和管理目标
			var p2 = jQuery.extend(true, {}, param);
			p2['monitorType']='drgs';
			var dateFrom = addMonth(param.dateFrom, -1);
			var dateTo = addMonth(param.dateTo, -1);
			p2.dateFrom = dateFrom;
			p2.dateTo = dateTo;
			ajaxRequest("Base", p2, function(data){
				datasyy = data;
				p2.compareType = compareType;
				if(compareType=='none'){//如果比较类型为无，则不获取比较值
					p2.isGetCc=0;
				}
				ajaxRequest(quotas.quotaCode_1, p2, function(data, quotaCode){
					if(datasyy && data) {
						mergeListcc(datasyy, data,'ccode','',quotaCode);
					}
					quotas.ajaxCount--;
				})
				ajaxRequest(quotas.quotaCode_2, p2, function(data, quotaCode){
					if(datasyy && data) {
						mergeListcc(datasyy, data,'ccode','',quotaCode);
					}
					quotas.ajaxCount--;
				})
			});
			//等待数据返回
			var timer = setInterval(function(){
				if(quotas.ajaxCount==0){
					clearInterval(timer);
					if(datas && datasyy) {
						datas =mergeList(datas, datasyy,'ccode','yy');
					}
					//数据处理
					var config = dataSolve(datas, quotas);
					//本期散点图
					quotas.config = config;
					quotas.data = datas;
					//执行排名算法,进行由好到坏的排序
					datasort = orderScatterData(quotas, datas);
					quotas.datasort = datasort;
					loadScatterChart1(quotas);
					loadQuadrantTable1(quotas, datas);
					quotas.loading = 1;
				}
			}, 500);
		})
		if(o==0) str.find("a").click();
	}
	//指标变化幅度按钮点击
	$("#"+tabId+" .btnslider").click(function(){
		var index = $(this).parent().find("li.active").find("a").attr("data-index");
		var quotas = quotass[index];
		var datasort = quotas.datasort;
		if($(this).hasClass("btn-success")){
			loadScatterChart2(datasort, quotas);
			$(this).removeClass("btn-success");
			$(this).addClass("btn-warning");
			quotas.chartType=0;
		}else{
			loadScatterChart1(quotas);
			loadQuadrantTable1(quotas, quotas.data)
			$(this).removeClass("btn-warning");
			$(this).addClass("btn-success");
			quotas.chartType=1;
		}
	})
	function ajaxRequest(quotaCode, param, callSure){
		param.quotaCode = quotaCode;
		$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(data){
			data = data.data;
			callSure(data, quotaCode);
		});
	}
	//处理数据,拼装echarts
	function dataSolve(datas, quotas){
		var xdirection = quotas.quotaDirection_1?quotas.quotaDirection_1:1;
		var ydirection = quotas.quotaDirection_2?quotas.quotaDirection_2:1;
		var xmin = 999999999;
		var xmax = -999999999;
		var ymin = 999999999;
		var ymax = -999999999;
		var symbolValueArray=[];
		for(var o in datas){
			symbolValueArray.push(datas[o].symbolValue);//决定散点图点的大小的值
			var quotaValue1 = datas[o][quotas.quotaCode_1];
			var quotaValue2 = datas[o][quotas.quotaCode_1+"cc"];
			if((quotaValue1||(compareType=='none'&&quotaValue1==0)) && (quotaValue2||(compareType=='none'&&quotaValue2==0))){
				var x = quotaValue1 - quotaValue2;
				datas[o].x = x;
			}
			
			var quotaValue3 = datas[o][quotas.quotaCode_2];
			var quotaValue4 = datas[o][quotas.quotaCode_2+"cc"];
			if((quotaValue3||(compareType=='none'&&quotaValue3==0)) && (quotaValue4||(compareType=='none'&&quotaValue4==0))){
				var y = quotaValue3 - quotaValue4;
				datas[o].y = y;
			}
			
			var quotaValue5 = datas[o][quotas.quotaCode_1+"yy"];
			var quotaValue6 = datas[o][quotas.quotaCode_1+"ccyy"];
			if((quotaValue5||(compareType=='none'&&quotaValue5==0)) && (quotaValue6||(compareType=='none'&&quotaValue6==0))){
				var x = quotaValue5 - quotaValue6;
				datas[o].x1 = x;
			}
			
			var quotaValue7 = datas[o][quotas.quotaCode_2+"yy"];
			var quotaValue8 = datas[o][quotas.quotaCode_2+"ccyy"];
			if((quotaValue7||(compareType=='none'&&quotaValue7==0)) && (quotaValue8||(compareType=='none'&&quotaValue8==0))){
				var y = quotaValue7 - quotaValue8;
				datas[o].y1 = y;
			}
			if(typeof(datas[o].x)!="undefined" && typeof(datas[o].y)!="undefined"){
				if(datas[o].x>=0 && datas[o].y>=0){
					datas[o].quadrant = 1;
					datas[o].color = '#f05a72';
				}else if(datas[o].x>0 && datas[o].y<0){
					datas[o].quadrant = 4;
					datas[o].color = '#fed503';
				}else if(datas[o].x<0 && datas[o].y>0){
					datas[o].quadrant = 2;
					datas[o].color = '#5bc0de';
				}else{
					datas[o].quadrant = 3;
					datas[o].color = '#66cc66';
				}
				if(datas[o].x<xmin)
				{xmin = datas[o].x;}
				if(datas[o].x>xmax)
				{ xmax = datas[o].x;}
				if(datas[o].y<ymin)
				{ ymin = datas[o].y;}
				if(datas[o].y>ymax)
				{ ymax = datas[o].y;}
				datas[o].x = datas[o].x.toFixed(2);//改为保留两位小数
				if(String(datas[o].y).split(".").length>1){
					datas[o].y = datas[o].y.toFixed(2);
				}
			}
			if(typeof(datas[o].x1)!="undefined" && typeof(datas[o].y1)!="undefined"){
				
				if(datas[o].x1<xmin)
				{xmin = datas[o].x1;}
				if(datas[o].x1>xmax)
				{ xmax = datas[o].x1;}
				if(datas[o].y1<ymin)
				{ ymin = datas[o].y1;}
				if(datas[o].y1>ymax)
				{ ymax = datas[o].y1;}
				
				datas[o].x1 = datas[o].x1.toFixed(2);//改为保留两位小数
				if(String(datas[o].y1).split(".").length>1){
					datas[o].y1 = datas[o].y1.toFixed(2);
				}
			}
		}
		//排序求最大最小值
		symbolValueArray.sort(function(a,b){return a-b;});
		var symbolValueMin=symbolValueArray[0];
		var symbolValueMax=symbolValueArray[symbolValueArray.length-1];
		
		xmin = Math.floor(xmin-0.2*Math.abs(xmin));
		ymin = Math.floor(ymin-0.2*Math.abs(ymin));
		xmax = Math.ceil(xmax+0.2*Math.abs(xmax));
		ymax = Math.ceil(ymax+0.2*Math.abs(ymax));
		var config = {"xmin":xmin,"xmax":xmax,"ymin":ymin,"ymax":ymax,symbolValueMin:symbolValueMin,symbolValueMax:symbolValueMax}
		return config;
	}
	//散点图
	function loadScatterChart1(quotas){
		var allGroupDayFeeChartData = [{"desc":"本期","data":quotas.data}];
		var sAxisDesc = quotas.quotaName_1.length>5?quotas.quotaName_1.substring(0,4)+"\n"+quotas.quotaName_1.substring(4):quotas.quotaName_1;
		var xyAx = {"xAxis":{"desc":sAxisDesc+"(0)"},"yAxis":{"desc":quotas.quotaName_2+"(0)"}};
		var compareName = '';
		if (compareType == "year") {
			compareName = "与同期差值";
		} else if (compareType == "month") {
			compareName = "与上期差值";
		} else if (compareType == "manage") {
			compareName = "与绩效差值";
		} else if (compareType == "std") {
			compareName = "与标杆差值";
		}else if (compareType == "hosp") {
			compareName = "与院内均值差值";
		}
		var chartParams=quotas.config;
		//散点图大小处理函数
		var symboSizeFunc=function(data){
			var region = chartParams.symbolValueMax-chartParams.symbolValueMin;
			if(region == 0)
			{
				region = 1;
			}
			//归一化处理
			return (((data[2]-chartParams.symbolValueMin)/region)*5+1)*10;
		}
		chartParams.symboSizeFunc=symboSizeFunc;
		chartParams.isDataZoom=true;
		//散点图提示框处理函数
		chartParams.formatterFunc=function (params) {
	    	//修改散点图悬浮框显示样式(黑框)
	    	var str="";
	    	str+=params.data.code+"("+params.name+ ")<br/>" +"("+params.data.value[0]+","+params.data.value[1]+")";
	    	if(chartParams.symbolValueMin&&chartParams.symbolValueMin){//如果添加总权重 用于求散点图点的大小，则在散点图中添加总权重的提示信息
	    		str+="<br/>总权重:" +params.data.value[2];
		    }
	    	return str;
    	};
    	//散点图点击事件
		chartParams.callBack_click=function(value){
			var data = value.data;
			var p = jQuery.extend(true, {}, param);
			if(value.data.desc==undefined){
				p.name = value.data.name;
			}else{
				p.name = "("+value.data.code+")"+value.data.desc;
			}
			p.drgCode = value.data.code;
			p.depCode = $("#"+tabId+" #depID").combobox("getValue");
			p.compareType=compareType;
			p.mrType=paramTabPage[tabId].mrType;
			if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
				if((data.value[0]>0&&data.value[1]>0) || (data.value[0]<0&&data.value[1]<0)){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal13Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee13', 'depKeyDisGroupAnalysisDetailDayFee13',p);
				}else if(data.value[0]<0&&data.value[1]>0){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal2Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee2', 'depKeyDisGroupAnalysisDetailDayFee2',p);
				}else if(data.value[0]>0&&data.value[1]<0){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal4Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee4', 'depKeyDisGroupAnalysisDetailDayFee4',p);
				}
			}
			if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
				openTab('/pages/keyDiseaseGroup/keyDisGroAnalFeeDrug.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailFeeDrug', 'depKeyDisGroupAnalysisDetailFeeDrug',p);
			}
		}
		scatterChartsWithLine($("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-chart"),allGroupDayFeeChartData,xyAx,quotas.quotaName_1+"和"+quotas.quotaName_2+compareName+"象限分析图",null,chartParams);
	}
	//散点线图
	function loadScatterChart2(dataf, quotas){
		var scatterChartData = [];
		var xAxis={"desc":quotas.quotaName_1+"(0)"};
		var yAxis={"desc":quotas.quotaName_2+"(0)"};
		for(var o in dataf){
			var data = dataf[o];
			if(data.x && data.y && data.x1 && data.y1 && data.per){
				var dataIndex=Number(data.index)+1;
				scatterChartData.push({"coords":[[data.x1,data.y1],[data.x, data.y]], value:data.per,index:dataIndex,code:data.ccode,desc:data.ccode+"("+data.ddesc+")",quadrant:data.quadrant});
			}
		}
		var chartParams={visualMap:true,isDataZoom:false};
		chartParams.callback_click = function(value){
			var data = value.data;
			var p = jQuery.extend(true, {}, param);
			if(value.data.desc==undefined){
				p.name = value.data.name;
			}else{
				p.name = "("+value.data.code+")"+value.data.desc;
			}
			p.drgCode = value.data.code;
			p.depCode = $("#"+tabId+" #depID").combobox("getValue");
			p.compareType=compareType;
			p.mrType=paramTabPage[tabId].mrType;
			if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
				if((data.value[0]>0&&data.value[1]>0) || (data.value[0]<0&&data.value[1]<0)){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal13Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee13', 'depKeyDisGroupAnalysisDetailDayFee13',p);
				}else if(data.value[0]<0&&data.value[1]>0){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal2Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee2', 'depKeyDisGroupAnalysisDetailDayFee2',p);
				}else if(data.value[0]>0&&data.value[1]<0){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnal4Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee4', 'depKeyDisGroupAnalysisDetailDayFee4',p);
				}
			}
			if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
				openTab('/pages/keyDiseaseGroup/keyDisGroAnalFeeDrug.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailFeeDrug', 'depKeyDisGroupAnalysisDetailFeeDrug',p);
			}
		}
		chartParams.callback_range = function(param){
			var range_s = param.selected[0];
			var range_e = param.selected[1];
			
			var datas1 = [];
			var length = dataf.length;
			range_s = range_s*length/100;
			range_e = range_e*length/100;
			range_e = range_e<length?range_e:length-1;
			for(var o=Math.ceil(range_s); o<=range_e; o++){
				var data = dataf[o];
				datas1.push(data);
			}
			loadQuadrantTable1(quotas, datas1);
		};
		chartParams.formatterFunc=function (params) {
        	var str="";
        	var index=Number(params.data.index);
        	str+=params.data.desc+":上期("+params.data.coords[0][0]+","+params.data.coords[0][1]+")<br>"+params.data.desc+":本期("+params.data.coords[1][0]+","+params.data.coords[1][1]+")<br>排名:"+index;        	
        	return str;
    	};
		var compareName = '';
		if (compareType == "year") {
			compareName = "同期";
		} else if (compareType == "month") {
			compareName = "上期";
		} else if (compareType == "manage") {
			compareName = "绩效";
		} else if (compareType == "std") {
			compareName = "标杆";
		}else if (compareType == "hosp") {
			compareName = "院内均值";
		}
		if(quotas.config && quotas.config.xmin!=undefined){
			xAxis.xmin = quotas.config.xmin;
		}
		if(quotas.config && quotas.config.xmax!=undefined){
			xAxis.xmax = quotas.config.xmax;
		}
		if(quotas.config && quotas.config.ymin!=undefined){
			yAxis.ymin = quotas.config.ymin;
		}
		if(quotas.config && quotas.config.ymax!=undefined){
			yAxis.ymax = quotas.config.ymax;
		}
		linesChartBasic($("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-chart"),scatterChartData,xAxis,yAxis,'',quotas.quotaName_1+"和"+quotas.quotaName_2+"与"+compareName+"差值象限分析图",'', chartParams);
		chartParams.callback_range({selected:[80,100]});
	}
	//四象限table方法
	function loadQuadrantTable1(quotas, datas){
		$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").each(function(i, n){
			$(n).find("td").eq(1).html("");
		})
		for(var o in datas){
			var data = datas[o];
			var dep = null;
			if($("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").eq(data.quadrant-1).find("td:eq(1) span").size()>0)
			{
				dep = $('<span><a href="javascript:void(0);">'+data.ccode+"("+data.ddesc+')</a></span>');
			}
			else
			{
				dep = $('<span><a href="javascript:void(0);">'+data.ccode+"("+data.ddesc+')</a></span>');
			}
			dep.data(data);
			dep.unbind("click");
			dep.bind("click", function(){
				var p = jQuery.extend(true, {}, param);
				var d = $(this).data();
				p.drgCode = d.ccode;
				p.depCode = $("#"+tabId+" #depID").combobox("getValue");
				p.name = d.ddesc;
				p.compareType=compareType;
				p.mrType=paramTabPage[tabId].mrType;
				
				if(quotas.quotaCode_1=="AvgDays" && quotas.quotaCode_2=="AvgFee"){
					if(d.quadrant==1 || d.quadrant==3){
						openTab('/pages/keyDiseaseGroup/keyDisGroAnal13Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee13', 'depKeyDisGroupAnalysisDetailDayFee13',p);
					}else if(d.quadrant==4){
						openTab('/pages/keyDiseaseGroup/keyDisGroAnal4Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee4', 'depKeyDisGroupAnalysisDetailDayFee4',p);
					}else if(d.quadrant==2){
						openTab('/pages/keyDiseaseGroup/keyDisGroAnal2Quad.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailDayFee2', 'depKeyDisGroupAnalysisDetailDayFee2',p);
					}
				}
				if(quotas.quotaCode_1=="AvgFee" && quotas.quotaCode_2=="DrugRatio"){
					openTab('/pages/keyDiseaseGroup/keyDisGroAnalFeeDrug.jsp', '重点病组分析病组详情','depKeyDisGroupAnalysisDetailFeeDrug', 'depKeyDisGroupAnalysisDetailFeeDrug',p);
				}
			})
			$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").eq(data.quadrant-1).find("td").eq(1).append(dep);
			$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").eq(data.quadrant-1).find("td").eq(1).append('<span>、</span>');
		}
		$("#"+tabId+" #depQuad"+quotas.quotaCode_1+quotas.quotaCode_2+"-table").find("tr").each(function(){
			if($(this).find("td").eq(1).html()!=''){
				$(this).find("td").eq(1).find('span').last().html('');
			}
		});
	}


	/**
	xdata x轴数据
	ydata y轴数据
	xstd x轴标杆
	ystd y轴标杆
	xdirection x指标方向 1正向 -1负向
	xdirection y指标方向 1正向 -1负向
	*/
	function orderScatterData(quotas, datas)
	{
		var xdirection = quotas.quotaDirection_1?quotas.quotaDirection_1:1;
		var ydirection = quotas.quotaDirection_2?quotas.quotaDirection_2:1;
		var datasort = [];
		for(var i=0;i<datas.length;i++)
		{
			var data = datas[i];
			var quotaValueRx = 0;
			var quotaValueRy = 0;
			if(data[quotas.quotaCode_1]!=null && data[quotas.quotaCode_1+"cc"]!=null&&data[quotas.quotaCode_1+"cc"]>0 && data[quotas.quotaCode_1+"yy"]!=null && data[quotas.quotaCode_1+"ccyy"]!=null&&data[quotas.quotaCode_1+"ccyy"]>0 && data[quotas.quotaCode_2]!=null && data[quotas.quotaCode_2+"cc"]!=null&&data[quotas.quotaCode_2+"cc"]>0 && data[quotas.quotaCode_2+"yy"]!=null && data[quotas.quotaCode_2+"ccyy"]!=null&&data[quotas.quotaCode_2+"ccyy"]>0){
				try{
					quotaValueRx = data[quotas.quotaCode_1]/data[quotas.quotaCode_1+"cc"] - data[quotas.quotaCode_1+"yy"]/data[quotas.quotaCode_1+"ccyy"];
					quotaValueRy = data[quotas.quotaCode_2]/data[quotas.quotaCode_2+"cc"] - data[quotas.quotaCode_2+"yy"]/data[quotas.quotaCode_2+"ccyy"];
					var l = Math.sqrt(Math.pow(quotaValueRx,2)+Math.pow(quotaValueRy,2));
					if(l==Infinity || l==-Infinity){
						data.l = 0;
					}else{
						if(xdirection*quotaValueRx>0&&ydirection*quotaValueRy>0) {
							//变好
							data.l = l;
						} else {
							//变差
							data.l = -l;
						}
					}
					datasort.push(data);
				}catch(e){
				}
			}
		}
		datasort.sort(function(a,b){return b.l-a.l});//降序
		var index = 0;//排名
		var length = datasort.length;
		for(var o in datasort){
			var data = datasort[o];
			var per = (index/length*100).toFixed(2);
			data.per = per;//名次
			data.index=index;
			index++;
		}
		return datasort;
	}
}

var depCodeNew =""; //科室代码

//重点病种筛选
function keyDisGroupFilter(){
	depCodeNew = $("#"+tabId+" #depID").combobox("getValue");
	 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
			var dialog  = $(data);
			dialog.find(".modal-dialog").attr("id","depkeyDiseaseGroupFilter_dialog_id");
			dialog.find(".modal-title").html("重点病组筛选");
			dialog.modal({
				keyboard: false
			}).on({'hidden.bs.modal' : function(){
					$(this).remove();
					searchByCondition();
				   },'shown.bs.modal' : function(){
					    var str="";
					    str+="";
					    str+=" <div class='row rowhcq'> ";
					    str+=" <div class='col-xs-12'> ";
					    str+="  <div class='boxcq clearfix'> ";
					    str+="     <div class='ti'><i class='fa fa-file-text-o'></i>科室重点病组筛选</div> ";
					    str+="      <ul class='nav nav-tabs boxnavcq' role='tablist'></ul> ";
					    str+="       <div class='clearfix'></div> "; 
					    str+="      <div class='col-xs-12' style = 'margin: 10px 0px;'> ";
					    str+="      	<div class='col-xs-6'> ";
					    str+="      		<div>    ";
					    str+="  			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>筛选时间范围</label> </div>  ";
					    str+=" 	            <div class='col-xs-3'> <select id = 'keyDisGroupSelect' class='multiselect ' multiple='multiple'> </select> </div>    ";
					    str+="             	<div class='col-xs-4'> <button class='form-control pull-right btn btn-success' onclick = 'setKeyDisGroup()'> 确定</button> </div>  ";
					    str+=" 	      </div>      ";
					    str+="     <div class='clearfix'> </div>   ";
					    str+="      		<div>   ";
					    str+="         			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>入组病例数占比排名前</label> </div>   ";
					    str+="              	<div class='col-xs-3'> <div class='input-group'>  <input class='form-control sliderValue' type='text' value = '80'/> <div class= 'input-group-addon'>%</div> </div> </div>  ";
					    str+="               	<div class='col-xs-4'> <input class='filterSlider' type='text'/> </div>  ";
					    str+="       		</div>  ";
					    str+="         		<div class='clearfix'></div>   ";
					    str+="    		<div>    ";
					    str+="   			    <div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>总权重占比排名前</label> </div>   ";
					    str+="   	            <div class='col-xs-3'> <div class='input-group'> <input class='form-control sliderValue' type='text' value = '80'/> <div class='input-group-addon'>%</div> </div> </div> ";  
					    str+="   	            <div class='col-xs-4'> <input class='filterSlider' type='text'/> </div>   ";
					    str+="           		</div>   ";
					    str+="          		<div class='clearfix'> </div>  ";
					    str+="          		<div>    ";
					    str+="           			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>各MDC内病组权重占比排名前</label> </div>   ";
					    str+="   	            	<div class='col-xs-3'> <div class='input-group'> <input class='form-control sliderValue' type='text' value = '80'/> <div class='input-group-addon' >%</div>  </div> </div>  ";
					    str+="   	            	<div class='col-xs-4'> <input class='filterSlider' type='text'/> </div>   ";
					    str+="          		</div>  ";
					    str+="          	</div>  ";
					    str+="       	<div class='col-xs-6'>   ";
					    str+="         		<div class='zhujie' style = 'padding:5px;line-height:30px; border-radius: 10px;box-shadow: 0 15px 80px rgba(0, 0, 0, .2);'>   ";
					    str+="        			1、将各DRG病组的入组病例数由高到低排名，取占总病组数排名前<span id = 'groupCntPer'>80</span>%病组；<br/>   ";
					    str+="        			2、将各DRG病组的总权重由高到低排名，取占总病组数排名前<span id = 'weightPer'>80</span>%病组；<br/>    ";
					    str+=" 					3、将各MDC内的DRG病组按照权重排名，取占总病组数排名前<span id = 'mdcWeightPer'>80</span>%病组；<br/>     ";
					    str+=" 					4、同时满足前三个条件病组为重点病组。     ";
					    str+="   		</div>    ";
					    str+="  	</div>       ";
					    str+="   </div>          ";
					    str+="   <div class='col-xs-12'> <div id='keyDisGroupMdcDiv'></div> </div>     ";
					    str+="   </div>     ";
					    str+="   </div>     ";
					    str+="   </div>     ";
					    
						dialog.find(".modal-dialog").width(1200);
						dialog.find(".modal-body").empty();
						dialog.find(".modal-body").append(str);
						var perConfig = [];
						var yearConfig = [];
						var years = [];
						//加载筛选时间范围
						$.ajax({
							url : contextPath + "/keyDisGroup/getKeyFilterInit.dhc",
							type : "post",
							dataType : "json",
							async : false,
							data : {code:depCodeNew},
							success : function(result) {
								years = result.data.years;
								var cfg = result.data.cfg;
								if(cfg!="")
								{
									yearConfig= cfg.split("θ")[0].split(",");
									perConfig= cfg.split("θ")[1].split(",");
								}
								var optStr = "";
								for(var i = 0;i<years.length;i++)
								{
									optStr = optStr + "<option value="+years[i]+">"+years[i]+"</option>";
								}
								dialog.find("#keyDisGroupSelect").append(optStr);
							}
						});
						//多选下拉框初始化
						if(yearConfig.length==0&&years.length>0){
							dialog.find(".multiselect").multiselect('select', years[years.length-1]);//截取最后一个
						}else if(yearConfig.length>0){
							dialog.find(".multiselect").multiselect('select', yearConfig);
						}
						if(perConfig.length==0){
							//调整滑块
							dialog.find(".filterSlider").slider({//把滑块的最小值调整到0
								min: 0, max: 100, range: false, value: 80,
							    reversed : false
							});
						}else{
							//调整滑块
							dialog.find(".filterSlider:eq(0)").slider({//把滑块的最小值调整到0
								min: 0, max: 100, range: false, value: perConfig[0],
							    reversed : false
							});
							dialog.find(".sliderValue:eq(0)").val(perConfig[0]);
							dialog.find("#groupCntPer").html(perConfig[0]);
							
							//调整滑块
							dialog.find(".filterSlider:eq(1)").slider({//把滑块的最小值调整到0
								min: 0, max: 100, range: false, value: perConfig[1],
							    reversed : false
							});
							dialog.find(".sliderValue:eq(1)").val(perConfig[1]);
							dialog.find("#weightPer").html(perConfig[1]);
							//调整滑块
							dialog.find(".filterSlider:eq(2)").slider({//把滑块的最小值调整到0
								min: 0, max: 100, range: false, value: perConfig[2],
							    reversed : false
							});
							dialog.find(".sliderValue:eq(2)").val(perConfig[2]);
							dialog.find("#mdcWeightPer").html(perConfig[2]);
						}
						dialog.find(".filterSlider:eq(0)").on("slide", function(slideEvt) {
							var groupCntPerValue=slideEvt.value;
							$(this).parent().parent().find("input:eq(0)").val(slideEvt.value);
							dialog.find("#groupCntPer").html(groupCntPerValue);
						});
						dialog.find(".filterSlider:eq(1)").on("slide", function(slideEvt) {
							var weightPerValue=slideEvt.value;
							$(this).parent().parent().find("input:eq(0)").val(weightPerValue);
							dialog.find("#weightPer").html(weightPerValue);
						});
						dialog.find(".filterSlider:eq(2)").on("slide", function(slideEvt) {
							var mdcWeightPerValue=slideEvt.value;
							$(this).parent().parent().find("input:eq(0)").val(mdcWeightPerValue);
							dialog.find("#mdcWeightPer").html(mdcWeightPerValue);
						});
						//input 框值改变事件
						dialog.find(".sliderValue:eq(0)").blur(function(e){  
							var perValue=$(this).val();
							if(!/^([1-9]\d?|100)$/.test(perValue))
							{
								drgUI.warning('请输入0-100之间的整数');
								$(this).val(80);
								dialog.find(".filterSlider:eq(0)").slider("setValue",80);
								dialog.find("#groupCntPer").html(80);
								return;
							}
							dialog.find(".filterSlider:eq(0)").slider("setValue",perValue);
							dialog.find("#groupCntPer").html(perValue);
						});
						dialog.find(".sliderValue:eq(1)").blur(function(e){  
							var perValue=$(this).val();
							if(!/^([1-9]\d?|100)$/.test(perValue))
							{
								drgUI.warning('请输入0-100之间的整数');
								$(this).val(80);
								dialog.find(".filterSlider:eq(1)").slider("setValue",80);
								dialog.find("#weightPer").html(80);
								return;
							}
							dialog.find(".filterSlider:eq(1)").slider("setValue",perValue);
							dialog.find("#weightPer").html(perValue);
						});
						dialog.find(".sliderValue:eq(2)").blur(function(e){  
							var perValue=$(this).val();
							if(!/^([1-9]\d?|100)$/.test(perValue))
							{
								drgUI.warning('请输入0-100之间的整数');
								$(this).val(80);
								dialog.find(".filterSlider:eq(2)").slider("setValue",80);
								dialog.find("#mdcWeightPer").html(80);
								return;
							}
							dialog.find(".filterSlider:eq(2)").slider("setValue",perValue);
							dialog.find("#mdcWeightPer").html(perValue);
						});
						dialog.find(".tooltip-arrow").css("display","none");
						dialog.find(".tooltip-inner").css("display","none");
						dialog.find(".slider").width(160);
						dialog.find("#keyDisGroupSelect").next(".btn-group").width(100);
						dialog.find("#keyDisGroupSelect").next(".btn-group").find("button").width(100);
						dialog.find(".sliderValue").width(66);
						
						showKeyDisGroupMdcLevel();//展示重点病组数据信息
						dialog.find(".modal-footer").css("display","none");
		              }
		      });

		});
}
/**
 * 设置重点病组
 */
function setKeyDisGroup(){
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_id");
	var caseRatio = newDialog.find(".filterSlider:eq(0)").val();//入组病例数占比
	var weightRatio = newDialog.find(".filterSlider:eq(1)").val();//总权重占比
	var mdcWeightRatio = newDialog.find(".filterSlider:eq(2)").val();//mdc权重占比
	var selected = [];
	newDialog.find(".multiselect option:selected").each(function () {
		selected.push($(this).val());
	});
	if(selected.length==0){
		drgUI.warning('年份不能为空');
		return ;
	}
	drgUI.confirm({
		content : '确认后原重点病组将被清除?',
		callSure : function() {
			$.post(contextPath + '/keyDisGroup/setKeyDisGroup.dhc',
				{
					"years":selected,
					"caseCntPer":caseRatio,
					"weightPer":weightRatio,
					"mdcWeightPer":mdcWeightRatio,
					"depCode":depCodeNew
				}
			).done(function(data){
				//显示遮罩层
				drgUI.success('本次确认'+data.data+'个重点病组');
				//清除全部缓存
				$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){
					
				})
				//重新加载新的重点病组数据
				showKeyDisGroupMdcLevel();
			});
		}
	});
}
/**
 * 从MDC 层次展示所有的重点病组
 */
function showKeyDisGroupMdcLevel()
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_id");
	//重点病组已经确定 重点病组的详细取决于-->>筛选时间范围
	var selected = [];
	newDialog.find(".multiselect option:selected").each(function () {
		selected.push($(this).val());
	});
	newDialog.find('#keyDisGroupMdcDiv').html('<table id="keyDisGroupMdcTable" class="table"></table>');
	$.post(contextPath+"/keyDisGroup/getKeyDisGroupDataMdc.dhc",{"years":selected,"depCode":depCodeNew,"hospCode":paramTabPage[tabId].hospCode}).done(function(result){
		var columns=[
	                  	{"data": "DRGS","sClass": "details-control"},
	                  	{"data": "MDCCODE","title":'MDC',
	                  		"render": function(obj, type, full) {
	                  			return "("+full["MDCCODE"]+")"+full["MDCDESC"];
		                      }
                  		},
	                  	{"data": "KEYGROUPCNT","title":'重点病组数' },
	                  	{"data": "CASECNT","title":'病例数',
                  			"render": function(obj, type, full) {
                  				if(full["CASECNT"]!=null) {
                  					return full["CASECNT"] ;
                  				} else {
                  					return "-" ;
              					}
		                      }
              			},
	                  	{"data": "TOTALWEIGHT","title":'总权重',
              				"render": function(obj, type, full) {
                  				if(full["TOTALWEIGHT"]!=null){
                  					return full["TOTALWEIGHT"] ; 
                  				} else {
                  					return "-";
              					}
		                      }
	                  	},
	                  	{"data": "CMI","title":'CMI',
	                  		"render": function(obj, type, full) {
                  				if(full["CMI"]!=null){
                  					return full["CMI"] ;
                  				} else {
                  					return "-";
              					}
		                      }
                  		}
	                 ];
		var paramsDataTables={lengthChange:false,ordering:false,stateSave:true,info:false,tableTitle:'重点病组MDC',columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		paramsDataTables.buttons=[{"text": '增加病组',"action": function ( e, dt, node, config) {showAddKeyDisGroupDlg();}},{"text": '重点病组明细',"action": function ( e, dt, node, config) {showKeyDisGroupDrgDlg();}}];
		var oaTable=newDialog.find("#keyDisGroupMdcTable").dataTableBasic(columns,result.data,paramsDataTables);
			function format ( d ) {
			    // `d` is the original data object for the row
			    return '<div class="col-xs-12" style="background:#eee;">'
					    +'	<div class="row">'
				        +'		<div class="col-xs-12" id= "'+d+'"></div>'
				        +'   </div>'
				        +'</div>';
			}
			newDialog.find('#keyDisGroupMdcTable tbody').on('click', 'td.details-control', function () {
				var nTr = $(this).closest('tr');
				var row = oaTable.row( nTr );
		        var aData = row.data();
		        if (row.child.isShown()) //判断是否已打开
				{
					row.child.hide();
					nTr.removeClass("shown");
				} else {
					nTr.addClass("shown");
		        	var mdcCode = aData.MDCCODE ;
		        	row.child(format(mdcCode)).show();
		            keyDisGroupInMdc(mdcCode);
		        }
		    } );
	});
}
/**
 * 新增重点病组
 */
function showAddKeyDisGroupDlg()
{
	 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
			var dialogadd  = $(data);
			dialogadd.find(".modal-dialog").attr("id","depkeyDiseaseGroupFilter_dialog_add");
			dialogadd.find(".modal-title").html("添加病组");
			dialogadd.modal({
				keyboard: false
			}).on({
				'hidden.bs.modal' : function(){
					$(this).remove();
				},
				'shown.bs.modal' : function(){
					dialogadd.find("#echartcq4").html("<table id = 'addKeyGroupTable' width = '100%'><thead><tr><th>MDC代码</th><th>MDC描述</th><th>DRG代码</th><th>DRG描述</th><th>病例数</th><th>病例数排名</th><th>权重</th><th>总权重</th><th>总权重排名</th><th>操作</th></tr></thead><tbody></tbody></table>");
					addKeyDisGroupTable();
				}
			});
	 });
}
/**
 * 新增重点病组详细
 * @returns
 */
function addKeyDisGroupTable()
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_add");
	var addKeyDisGroupTableData = getExtraDisGroup();
	var columns=[	
                 {"data": "MDCCODE"},
                 {"data": "MDCDESC",
             	  "render": function(obj, type, full) {
             		  if(full["MDCDESC"]==null) {
             			  return full["MDCCODE"] ;
         			  } else {
         				  return "-";
     				  }
             	  }
                 },
               	{"data": "DRGCODE" },
               	{"data": "DRGDESC",
           			"render": function(obj, type, full) {
	              				if(full["DRGDESC"]!=null) {
	              					return full["DRGDESC"] ;
	              				} else {
	              					return "-";
	          					}
	                      }
       			},
               	{"data": "CASECNT",
       				"render": function(obj, type, full) {
           					if(full["CASECNT"]!=null){
           						return full["CASECNT"] ;
           					} else {
               					return "-";
           					}
	                      }
   				},
               	{"data": "CASECNTRANGE",
   					"render": function(obj, type, full) {
       						if(full["CASECNTRANGE"]!=null){
       							return full["CASECNTRANGE"] ;
       						} else {
               					return "-";
           					}
	                      }
					},
               	{"data": "WEIGHT",
						"render": function(obj, type, full) {
	  							if(full["WEIGHT"]!=null) {
	  								return full["WEIGHT"] ;
	  							} else {
	              					return "-";
	          					}
	                      }
					},
               	{"data": "TOTALWEIGHT",
						"render": function(obj, type, full) {
								if(full["TOTALWEIGHT"]!=null){
									return full["TOTALWEIGHT"] ;
	  							} else {
	              					return "-";
	          					}
	                      }
						},
               	{"data": "TOTALWEIGHTRANGE",
							"render": function(obj, type, full) {
								if(full["TOTALWEIGHTRANGE"]!=null){
									return full["TOTALWEIGHTRANGE"] ;
   							} else {
               					return "-";
           					}
	                      }
           		},
               	{"data": "operation",
               		"render": function(obj, type, full) {
               			return "<a href = \"javascript:addKeyDisGroup('"+full["DRGCODE"]+"')\">添加</a>";
	                      }
           		}
              ];
	var paramsDataTables={lengthChange:false,info:false,columnDefs:[{"orderable": false,"targets": [ 9 ] },{ "visible": false, "targets": [1]}]};
	newDialog.find("#echartcq4 #addKeyGroupTable").dataTableBasic(columns,addKeyDisGroupTableData,paramsDataTables);
}
/**
 * 获取重点病组以外的病组 让用户筛选
 */
function getExtraDisGroup()
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_id");
	var selected = [];
	newDialog.find(".multiselect option:selected").each(function () {
		selected.push($(this).val());
	});
	var data = [];
	$.ajax({
		url : contextPath + "/keyDisGroup/getExtraDisGroup.dhc",
		type : "post",
		dataType : "json",
		data : {
			"years":selected,
			"depCode":depCodeNew,
			"hospCode":paramTabPage[tabId].hospCode
		},
		async : false,
		success : function(result) {
			data = result.data;
		}
	});
	return data

}
/**
 * 添加重点病组
 * @param drgCode
 */
function addKeyDisGroup(drgCode)
{
	$.post(contextPath + '/keyDisGroup/addKeyDisGroup.dhc',{"drgCode":drgCode,"depCode":depCodeNew}).done(function(data){
		//清除全部缓存
		$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
		//刷新当前表格和mdc表格
		showKeyDisGroupMdcLevel();
		addKeyDisGroupTable();
		drgUI.success('添加病组成功');
	});
}
/**
 * 重点病组详细对话框
 */
function showKeyDisGroupDrgDlg()
{
	 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
			var dialog  = $(data);
			dialog.find(".modal-title").html("重点病组明细");
			dialog.find(".modal-dialog").attr("id","depkeyDiseaseGroupFilter_dialog_dis");
			dialog.modal({
				keyboard: false
			}).on({
				'hidden.bs.modal' : function(){
					$(this).remove();
				},
				'shown.bs.modal' : function(){
					dialog.find("#echartcq4").html("<table id = 'keyGroupDetailTable' width = '100%' ><thead><tr><th>MDC代码</th><th>MDC描述</th><th>DRG代码</th><th>DRG描述</th><th>病例数</th><th>病例数排名</th><th>权重</th><th>总权重</th><th>总权重排名</th><th>操作</th></tr></thead><tbody></tbody></table>");
					keyDisGroupDrgDataTable()
				}
			});
	 });
}

/**
 * 某个mdc下的重点病组
 * @param mdc
 */
function keyDisGroupInMdc(mdc)
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_id");
    var tid='id'+new Date().getTime();
    var mdcTableData = getKeyDisGroupDataDrg(mdc);
    newDialog.find('#'+mdc).html('<table id="'+tid+'" class="table"></table>');
	var columns=[
               	{"data": "DRGINFO","title":'DRG代码及描述',
              		"render": function(obj, type, full) {
          				if(full["DRGDESC"]!=null)
      					{
          					return "("+full["DRGCODE"]+")"+full["DRGDESC"];
      					}
          				else
      					{
          					return "("+full["DRGCODE"]+")";
      					}
                      }
          		},
              	{"data": "CASECNT","title":'病例数',
          			"render": function(obj, type, full) {
          				if(full["CASECNT"]!=null)
      					{
          					return full["CASECNT"];
      					}
          				else
      					{
          					return "-";
      					}
                      }
          		},
              	{"data": "TOTALWEIGHT","title":'总权重',
          			"render": function(obj, type, full) {
          				if(full["TOTALWEIGHT"]!=null)
      					{
          					return full["TOTALWEIGHT"];
      					}
          				else
      					{
          					return "-";
      					}
                      }
          		},
              	{"data": "WEIGHT","title":'权重',
          			"render": function(obj, type, full) {
          				if(full["WEIGHT"]!=null)
      					{
          					return full["WEIGHT"];
      					}
          				else
      					{
          					return "-";
      					}
                      }
          		},
              	{"data": "operation","title":'操作',
              		"render": function(obj, type, full) {
              			return "<a href = \"javascript:delKeyDisGroup('"+full.DRGCODE+"','mdclevel')\">删除</a>";
	            	   }
          		}
             ];
	var paramsDataTables={tableTitle:mdc+'-重点病组',lengthChange:false,ordering:false,stateSave:true,info:false,columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
	newDialog.find("#"+tid).dataTableBasic(columns,mdcTableData,paramsDataTables);
}
/**
 * 按照DRG层级获取重点病组的详情
 * @param mdc 当mdc为空时查询所有mdc下的drg,当mdc不为空时查询特定mdc下的drg
 */
function getKeyDisGroupDataDrg(mdc)
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_id");
	var selected = [];
	newDialog.find(".multiselect option:selected").each(function () {
		selected.push($(this).val());
	});
	var data = [];
	$.ajax({
		url : contextPath + "/keyDisGroup/getKeyDisGroupDataDrg.dhc",
		type : "post",
		dataType : "json",
		data : {
			"years":selected,
			"mdcCode":mdc,
			"depCode":depCodeNew,
			"hospCode":paramTabPage[tabId].hospCode
		},
		async : false,
		success : function(result) {
			data = result.data;
		}
	});
	return data;
}
/**
 * 删除重点病组
 * @param drg drg代码
 * @param level 层级
 */
function delKeyDisGroup(drg,level)
{
	drgUI.confirm({
		content : '确认删除吗?',
		callSure : function() {
			$.post(contextPath +"/keyDisGroup/delKeyDisGroup.dhc",{'drgCode':drg,'depCode':depCodeNew},function(result){
				
				if(level=="mdclevel")
				{
					showKeyDisGroupMdcLevel();//重新加载MDC层级重点病组的详情
				}
				else
				{
					showKeyDisGroupMdcLevel();//重新加载MDC层级重点病组的详情
					keyDisGroupDrgDataTable();//重新加载DRG层级重点病组的详情
				}
				//清除全部缓存
				$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
			});
		}
	});
	
}

/**
 * 从drg层次展示重点病组信息
 * @param container 对话框容器
 * @param id table的id
 */
function keyDisGroupDrgDataTable()
{
	var newDialog=$("#depkeyDiseaseGroupFilter_dialog_dis");
	var keyGroupDetailTableData = getKeyDisGroupDataDrg();
	var columns=[
                 {"data": "MDCCODE" },
                 {"data": "MDCDESC",
             	  "render": function(obj, type, full) {
             		  if(full["MDCDESC"]!=null) {
             			  return full["MDCDESC"] ;
             		  } else {
         				  return "-";
     				  }
             	  }
                 },
               	{"data": "DRGCODE" },
               	{"data": "DRGDESC",
           			"render": function(obj, type, full) {
           				if(full["DRGDESC"]!=null) {
           					return full["DRGDESC"] ;
           				}
           				else {
           					return "-";
       					} 
	                     }
       			},
               	{"data": "CASECNT",
       				"render": function(obj, type, full) {
       					if(full["CASECNT"]!=null) {
       						return full["CASECNT"];
       					} else   {
           					return "-";
       					}
	                      }
   				},
               	{"data": "CASECNTRANGE",
   					"render": function(obj, type, full) {
   						if(full["CASECNTRANGE"]!=null){
   							return full["CASECNTRANGE"] ;
   						} else {
           					return "-";
       					} 
	                      }
					},
               	{"data": "WEIGHT",
						"render": function(obj, type, full) {
							if(full["WEIGHT"]!=null) {
								return full["WEIGHT"] ;
							} else {
           					return "-";
       					}
	                      }
					},
               	{"data": "TOTALWEIGHT",
						"render": function(obj, type, full) {
							if(full["TOTALWEIGHT"]!=null) {
								return full["TOTALWEIGHT"] ;
							} else {
           					return "-";
       					}
	                      }
						},
               	{"data": "TOTALWEIGHTRANGE",
						"render": function(obj, type, full) {
							if(full["TOTALWEIGHTRANGE"]!=null) {
								return full["TOTALWEIGHTRANGE"] ;
							} else {
								return "-";
							}
                     }
           		},
               	{"data": "operation",
               		"render": function(obj, type, full) {
               			return "<a href = \"javascript:delKeyDisGroup('"+full.DRGCODE+"','drglevel')\">删除</a>";//将full[0]改为full[2]   重点病组明细删除
	                      }
           		}
              ];
	var paramsDataTables={lengthChange:false,searching:false,stateSave:true,info:false,tableTitle:'',columnDefs:[{"orderable": false,"targets": [ 9 ] },{ "visible": false, "targets": [1]}]};
	newDialog.find("#echartcq4 #keyGroupDetailTable").dataTableBasic(columns,keyGroupDetailTableData,paramsDataTables);
}